package com.meme.io.packager;

import com.meme.editor.EntityObject;
import com.meme.editor.level.define.*;
import com.meme.editor.level.Actor;
import com.meme.editor.property.*;
import com.meme.editor.property.value.*;

import java.io.RandomAccessFile;
import java.util.List;
import java.util.LinkedList;

import org.apache.log4j.Logger;

public class PropertyWriter 
{
	static Logger logger = Logger.getLogger(PropertyWriter.class);
	
	
	public static void writePropertyList (List<Property> propertyList, RandomAccessFile binFile, PropertyWriterContext propertyWriterContext)
	                                 throws Exception
	{
		for (Property property : propertyList)
		{
			writeProperty (property, binFile, propertyWriterContext);
		}
	}
	
	public static void writeProperty (Property property, RandomAccessFile binFile, PropertyWriterContext propertyWriterContext)
									 throws Exception
	{
		String valueType = property.getValueType();
		
		if (valueType.equals (PropertyFactory.ValueType_Boolean))
		{
			Boolean booleanValue = (Boolean) property.getValue();
			binFile.writeShort (booleanValue.booleanValue() ? 0 : 1);
		}
		else if (valueType.equals (PropertyFactory.ValueType_Number))
		{
			// temp, only support integer, not support float, 
			Float floatValue = (Float) property.getValue();
			binFile.writeShort (floatValue.intValue());
		}
		else if (valueType.equals (PropertyFactory.ValueType_Items))
		{

		}
		else if (valueType.equals (PropertyFactory.ValueType_EntityRef))
		{
			
		}
		else if (valueType.equals (PropertyFactory.ValueType_String))
		{
			// temp, not support
		}
		else
		{
			logger.error ("Unknown property value type: " + valueType);
		}
		
	}
	

	


}
